#ifndef _MCMC_CHANGE_ATOMIC_REGION_H
#define _MCMC_CHANGE_ATOMIC_REGION_H

#include "mcmcLayerRegion.h"

//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
class MCMC_AtomicRegion_Record
{
public:
	// construnction & destruction
	MCMC_AtomicRegion_Record();
	~MCMC_AtomicRegion_Record();

	void	Empty(void);

	// operators
	MCMC_AtomicRegion_Record & operator=(MCMC_AtomicRegion &a);

	// access
	inline int		IndexIdNew(void) const {return indexid_new;};
	inline bool		GetFirstPixel(int &j, int &i) {return domain.GetFirst(j, i);};
	inline bool		GetNextPixel(int &j, int &i) {return domain.GetNext(j, i);};
	inline MCMC_Model *Model(void){return pmodel;};

protected:
	int				indexid_new;
	MCMC_Model		*pmodel;
	MCMC_PixelSet	domain;
};


//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
class MCMC_GRegion_Record
{
public:
	// construction & destruction
	MCMC_GRegion_Record();
	~MCMC_GRegion_Record();

	void	Empty(void);

	// operators
	MCMC_GRegion_Record & operator=(MCMC_GRegion &a);

	// access
	inline	void	SetNewIndexId(const int index){indexid_new=index;}
	inline	int		IndexIdNew(void){return indexid_new;};
	inline	void	SetIndexTable(mcmcVector<int> &vc_index_table){pvc_index_table=&vc_index_table;};
	inline	bool	GetFirstChild(int &i) {return list_indexid.GetFirst(i);};
	inline	bool	GetNextChild(int &i) {return list_indexid.GetNext(i);};
	inline MCMC_Model *Model(void){return pmodel;};

protected:
	int				indexid_new;
	MCMC_Model		*pmodel;
	mcmcVector<int>		*pvc_index_table;
	LinkList<int>	list_indexid;
};


//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
class MCMC_LayerRegion_Record
{
public:
	// construction & destruction
	MCMC_LayerRegion_Record();
	~MCMC_LayerRegion_Record();
	
	void Empty();
	
	// operator
	virtual void Remember(MCMC_Layer_Regions &layer_region);

	inline	MCMC_AtomicRegion_Record*	GetARegionRecord(const int i){return &(p_aregion_record[i]);};
	inline  MCMC_GRegion_Record*		GetGRegionRecord(const int i){return &(p_gregion_record[i-num_aregions]);};

	virtual bool	RePartitionAtomicRegions(MCMC_Layer_Regions &layer_region, Raster<int> &ras_label_map);
	virtual bool	RePartitionAtomicRegions(LinkList<int> &list_new_aregions, MCMC_Layer_Regions &layer_region,
											 LinkList<int> &list_aregion_tochange, Raster<int> &ras_label_map);
	
protected:
	virtual void	WhoTakesMost(LinkList<int> *p_list, MCMC_Layer_Regions &a);
	virtual void	Recover(MCMC_Layer_Regions &a);
	inline	bool	IsAtomic(const int i) {if (i<num_aregions) return true; else return false;}

	inline	int		Id4IndexId(const int index) {return vc_index_table.Data(index);};

protected:
	MCMC_AtomicRegion_Record	*p_aregion_record;
	int		num_aregions;

	MCMC_GRegion_Record			*p_gregion_record;
	int		num_gregions;

	mcmcVector<int>		vc_index_table;
	mcmcVector<char>	vc_aregion_sign;
	Raster<int>		ras_partition_map_new;
	Raster<int>		ras_partition_map_old;
};



#endif